package com.qf2207.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.qf2207.bo.DevicesBo;
import com.qf2207.pojo.Devices;
import com.qf2207.service.DevicesService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/*
 * @Author LX
 * @Date 2022/7/21    22:20
 * @Version 3.3
 */
@Component
@Scope("prototype")//这里一定要设置为多例模式
public class WebDevicesListener extends AnalysisEventListener<DevicesBo> {
    @Autowired
    DevicesService devicesService;

    @Override
    public void invoke(DevicesBo data, AnalysisContext analysisContext) {
        System.out.println("读取到的Excel中的数据：" + data);
        Devices paper = new Devices();
//        student.setName(data.getName());
        //属性拷贝
        BeanUtils.copyProperties(data,paper);
        devicesService.addDevices(paper);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("数据获取执行完成！！！");
    }
}
